<!--
	- computeAnalysis.php
	- v0.01
	- 3/4/2011
	- This is a php file containing functions that compute the different analysis.
	-->

<?php
	/* function that computes percent of carbohydrate */
	function ComputeCarbohydrate($A, $B, $C, $D, $E){
		$Carb = 100 - ($A + $B + $C + $D + $E);
		return $Carb;
	}
	
	/* function that computes percent of ash content */
	function ComputeAshContent($A, $B, $C){
		$Ash = (($C - $A) / $B) * 100;
		return $Ash;
	}
	
	/* function that computes percent of moisture content */
	function ComputeMoistureContent($A, $B, $C){
		$MC = (($C - $A) / $B) * 100;
		return $MC;
	}
	
	/* function that computes percent of crude fiber */
	function ComputeCrudeFiber($A, $B, $C){
		$CF = (($B - $C) / $A) * 100;
		return $CF;
	}
	
	/* function that computes percent of crude fat */
	function ComputeCrudeFat($A, $B, $C){
		$CFat = (($C - $A) / $B) * 100;
		return $CFat;
	}
	
	/* function that computes percent of crude protein */
	function ComputeCrudeProtein($A, $B, $C, $factor){
		$N = ((($A - $B) / $C) * 3.75) * 100;
		$CP = $N / $factor;
		return $CP;
	}

	/* function that computes the total energy */
	function ComputeTotalEnergy($A, $B, $C){
		$energy = 4*$A + 9*$B + 4*$C;
		return $energy;
	}
	
	function ComputeMean($A, $B, $C, $n){
		$mean = ($A + $B + $C) / $n;
		return $mean;
	}
	
	function ComputeStandardDeviation($A, $B, $C){
		$standardDeviation = sqrt( (pow(($A-$C),2) + pow(($B-$C),2)) / 1 );
		return $standardDeviation;
	}
	
	function ComputeStandardDeviationOthers($A, $B, $C, $D, $n){
		$standardDeviation = sqrt( (pow(($A-$D),2) + pow(($B-$D),2) + pow(($C-$D),2)) / $n-1 );
		return $standardDeviation;
	}
?>